# Copyright (C) 2002-2007 The Written Word, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# $Id: configure.ac 694 2010-02-19 14:55:45Z china $

AC_INIT(sbutils, 1.3.1)
AC_CONFIG_SRCDIR([bin/sb])

AC_PROG_CC
AC_C_INLINE
AC_PROG_INSTALL

AC_CHECK_HEADERS([fnmatch.h])
AC_CHECK_FUNCS([strdup strcasecmp])

AC_PATH_PROGS(BASH, bash)
if test "x$BASH" = "x"; then
  AC_MSG_ERROR([Unable to find path to "bash" shell])
fi

AC_PATH_PROGS(PYTHON, python)
if test "x$PYTHON" = "x"; then
  AC_MSG_ERROR([Unable to find path to "python" shell])
else
  AC_MSG_CHECKING([if $PYTHON is at least 2.5])
  _python_major_ver=`$PYTHON -V 2>&1 |\
sed "s!Python \(@<:@0-9@:>@@<:@0-9@:>@*\).*!\1!"`
  _python_minor_ver=`$PYTHON -V 2>&1 |\
sed "s!Python @<:@0-9@:>@@<:@0-9@:>@*\.\(@<:@0-9@:>@@<:@0-9@:>@*\).*!\1!"`
  if test "$_python_major_ver" -lt 2; then
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([Version of Python must be at least 2.5])
  fi
  if test "$_python_major_ver" -eq 2 -a "$_python_minor_ver" -lt 5; then
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([Version of Python must be at least 2.5])
  fi
  AC_MSG_RESULT([yes])  

  AC_MSG_CHECKING([if Python fchksum module is available])
  if ($PYTHON -c 'import fchksum') 2>/dev/null; then
    AC_MSG_RESULT([yes])
  else
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([Python fchksum module required])
  fi

  AC_MSG_CHECKING([if Python pycurl module is available])
  if ($PYTHON -c 'import pycurl') 2>/dev/null; then
    AC_MSG_RESULT([yes])
  else
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([Python pycurl module required])
  fi

  AC_MSG_CHECKING([if Python lxml module is available])
  if ($PYTHON -c 'import lxml.etree') 2>/dev/null; then
    AC_MSG_RESULT([yes])
  else
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([Python lxml module required])
  fi
fi


AC_PATH_PROGS(AWK, gawk)
AC_PATH_PROGS(CHGRP, gchgrp)
AC_PATH_PROGS(CHMOD, gchmod)
AC_PATH_PROGS(CHOWN, gchown)
AC_PATH_PROGS(CPIO, gcpio)
AC_PATH_PROGS(FIND, gfind)
AC_PATH_PROGS(EGREP, gegrep)
AC_PATH_PROGS(INSTALL, ginstall)
AC_PATH_PROGS(LN, gln)
AC_PATH_PROGS(TAR, gtar)
AC_PATH_PROGS(TOUCH, gtouch)
AC_PATH_PROGS(SED, gsed)
AC_PATH_PROGS(UNZIP, unzip)

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
